package com.quiz.bis.controller;

import com.quiz.bis.domain.model.QuestionType;
import com.quiz.bis.service.IQuestionTypeService;
import com.quiz.common.core.controller.BaseController;
import com.quiz.common.core.domain.R;
import com.quiz.common.mybatis.core.page.TableDataInfo;
import com.quiz.common.mybatis.core.page.PageQuery;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * 题目类型管理
 *
 * @author ahuan
 */
@RestController
@RequestMapping("question2/type")
@Tag(name = "题目类型管理")
@RequiredArgsConstructor
public class QuestionTypeController extends BaseController {

    private final IQuestionTypeService baseService;

    /**
     * 分页查询题目类型列表
     *
     * @param questionType 查询参数
     * @param page 分页参数
     * @return {@link TableDataInfo}<{@link QuestionType}> 分页结果
     */
    @GetMapping("page")
    @Operation(summary = "分页查询题目类型列表")
    public TableDataInfo<QuestionType> page(QuestionType questionType, PageQuery page) {
        return baseService.page(questionType, page);
    }

    /**
     * 不分页查询题目类型列表
     *
     * @param questionType 查询参数
     * @return {@link R}<{@link List}<{@link QuestionType}>> 分页结果
     */
    @GetMapping("list")
    @Operation(summary = "不分页查询题目类型列表")
    public R<List<QuestionType>> list(QuestionType questionType) {
        return R.ok(baseService.list(questionType));
    }

    /**
     * 获取题目类型详细信息
     *
     * @param id 题目类型ID
     * @return {@link R}<{@link QuestionType}> 题目类型信息
     */
    @GetMapping("{id}")
    @Operation(summary = "获取题目类型详细信息")
    public R<QuestionType> getById(@PathVariable Long id) {
        return R.ok(baseService.getById(id));
    }

    /**
     * 新增题目类型
     *
     * @param questionType 题目类型信息
     * @return {@link R}<{@link Void}> 操作结果
     */
    @PostMapping
    @Operation(summary = "新增题目类型")
    public R<Void> save(@Valid @RequestBody QuestionType questionType) {
        return toR(baseService.save(questionType));
    }

    /**
     * 修改题目类型
     *
     * @param questionType 题目类型信息
     * @return {@link R}<{@link Void}> 操作结果
     */
    @PutMapping
    @Operation(summary = "修改题目类型")
    public R<Void> update(@Valid @RequestBody QuestionType questionType) {
        return toR(baseService.update(questionType));
    }

    /**
     * 删除题目类型
     *
     * @param ids 题目类型ID数组
     * @return {@link R}<{@link Void}> 操作结果
     */
    @DeleteMapping("{ids}")
    @Operation(summary = "删除题目类型")
    public R<Void> delete(@PathVariable Long[] ids) {
        return toR(baseService.deleteByIds(ids));
    }
}